package cn.zl.mapper;

import cn.yunbamboos.mybatis.annotation.CustomQuery;
import cn.yunbamboos.mybatis.annotation.GenerateXML;
import cn.yunbamboos.mybatis.conditions.Conditions;
import cn.yunbamboos.mybatis.mapper.GenericMapper;
import cn.zl.model.Device;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;


@GenerateXML
@Repository
public interface DeviceMapper extends GenericMapper<Device> {

    default boolean existDeviceId(@Param("device_id") String deviceId){
        return this.queryForObject(Conditions.create("device_id", deviceId)).isPresent();
    }

    default Device queryByDeviceId(@Param("device_id") String deviceId){
        return this.queryForObject(Conditions.create("device_id", deviceId)).orElse(null);
    }

    @CustomQuery(sql = "select count(1) from zl_device where on_line=1", resultType = Integer.class)
    int countOnLine();

    @CustomQuery(sql = "select count(1) from zl_device", resultType = Integer.class)
    int total();

}
